package com.cloud.applogic;

import com.cloud.models.Browser;
import com.cloud.util.PropertyLoader;
import com.cloud.webdriver.WebDriverFactory;
import org.openqa.selenium.WebDriver;

public class ApplicationManager {

    private String gridHubUrl;
    private String username;
    private String password;
    private String baseUrl;
    private Browser browser;
    private WebDriver driver;
    public UserHelper userHelper;
    public LoginHelper loginHelper;
    public NavigationHelper navHelper;
    public ProfileHelper profileHelper;
    public RegisterHelper registerHelper;
    public ForgotPassHelper forgotPassHelper;
    public StaticPagesHelper staticPagesHelper;

    public ApplicationManager() {

        //Get properties (from application.properties)
        gridHubUrl = PropertyLoader.loadProperty("grid2.hub");
        browser = new Browser();
        browser.setName(PropertyLoader.loadProperty("browser.name"));
        browser.setVersion(PropertyLoader.loadProperty("browser.version"));
        browser.setPlatform(PropertyLoader.loadProperty("browser.platform"));
        username = PropertyLoader.loadProperty("user.username");
        password = PropertyLoader.loadProperty("user.password");
        baseUrl = PropertyLoader.loadProperty("site.url");

        //Create browser (using given properties)
        driver = WebDriverFactory.getInstance(gridHubUrl, browser, username, password);

        //Create helpers
        navHelper = new NavigationHelper(this);
        userHelper = new UserHelper(this);
        loginHelper = new LoginHelper(this);
        profileHelper = new ProfileHelper(this);
        registerHelper = new RegisterHelper(this);
        forgotPassHelper = new ForgotPassHelper(this);
        staticPagesHelper = new StaticPagesHelper(this);

        //Open main page
        driver.manage().window().maximize();
        driver.get(baseUrl);

    }

    //Getters
    protected WebDriver getWebDriver() {
        return driver;
    }
    protected String getBaseUrl() {
        return baseUrl;
    }

    //Close browser
    public void stop() {
        if (driver != null) {
            driver.quit();
        }
    }

}
